package com.qingmi.farmer.data.repository.api;

import com.qingmi.farmer.data.model.GoodsInfo;
import com.qingmi.farmer.data.model.GoodsOrder;
import com.qingmi.farmer.data.model.GoodsType;
import com.qingmi.farmer.data.model.Supplier;
import com.qingmi.farmer.data.model.Trolley;
import com.wjjun.base.data.net.HTTPSService;
import com.wjjun.base.data.preference.UserPreference;
import com.qingmi.farmer.data.request.GetGoodsListReq;
import com.qingmi.farmer.data.request.GetGoodsOrderListReq;
import com.qingmi.farmer.data.request.GetGoodsTypeReq;
import com.qingmi.farmer.data.request.GetSupplierReq;
import com.wjjun.basemvpvm.data.model.PageEntity;
import com.wjjun.basemvpvm.data.net.HttpApiManager;
import com.wjjun.basemvpvm.data.net.filter.BaseResponseFilter;
import com.wjjun.basemvpvm.data.repository.BaseApiRepository;
import com.wjjun.basemvpvm.data.request.SimpleRequest;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * 生资模块
 * Created by 67535 on 2018/5/23.
 */
public class GoodsApiRepository extends BaseApiRepository {

    private UserPreference userPreference;

    @Inject
    public GoodsApiRepository(HttpApiManager httpApiManager, BaseResponseFilter filter, UserPreference userPreference) {
        super(httpApiManager, filter);
        this.userPreference = userPreference;
    }

    /**
     * 获取全部商品
     */
    public Observable<PageEntity<List<GoodsInfo>>> getGoodsList(GetGoodsListReq req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGoodsList(req.toMap(), userPreference.getToken()));
    }

    /**
     * 获取单个商品详情
     */
    public Observable<GoodsInfo> getGoodsDetail(SimpleRequest req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGoodsDetail(req.getId(), userPreference.getToken()));
    }


    /**
     * 获取厂商信息
     */
    public Observable<List<Supplier>> getSupplier(GetSupplierReq req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getSupplier(req.toMap()));
    }


    /**
     * 获取商品类型
     */
    public Observable<List<GoodsType>> getGoodsType(GetGoodsTypeReq req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGoodsType(req.toMap()));
    }

    /**
     * 获取购物车数据
     */
    public Observable<List<Trolley>> getTrolley() {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getTrolley(userPreference.getToken()));
    }

    /**
     * 获取生资订单列表
     */
    public Observable<List<GoodsOrder>> getGoodsOrderList(GetGoodsOrderListReq req) {
        return res2Entity(httpApiManager.getService(HTTPSService.class).getGoodsOrderList(req.toMap(), userPreference.getToken()));
    }

}

